<template>
	<view>
		<!-- 头部 -->
		<view class="head" style="width: 100%; height: 55px; background-color: rgba(31, 138, 243, 1);">
			<view class="search">
				<uni-search-bar class="uni-mt-10"
					v-model="filterText"
					radius="5"
					placeholder="在研知音搜索专业课"
					clearButton="auto"
					cancelButton="none"
					confirm-type="search"
					@confirm="search"
					@input="input"
					@focus="onclick()"
				/>
			</view>
		</view>

		<!-- 商品 -->
		<view class="body">
			<view class="goods"
				v-for="(item,index) in dataList"
				:key="index"
			>
				<image :src="item.imgUrl" mode="aspectFit"></image>
				<view class="content" @click="information(item.id)">
					<text>{{item.name}}</text>
					<view class="content1">
						<text class="price">￥{{item.price}}</text>
						<text class="time">{{item.uploadTime_}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import axios from 'axios'
	export default{
		data(){
			return {
				filterText:'',
				dataList:[],
			}
		},
		created() {
			// this.getListData()
			this.$axios.get("/goods/search",{
				params:{
					key:'',
				},
				headers:{
					'token':localStorage.getItem('token')
        }
			}).then(res=>{

          //mgladd 判断文件类型，如果文件类型为0，显示为pdf的图片，类型为1或者2，显示word
          res.data.data.map(item => {
            if (item.fileType === 0)
				item.imgUrl = '../../static/pdficon.jpeg'
            else if (item.fileType === 1 || item.fileType ===2)
				item.imgUrl = '../../static/docIcon.jpg'
            else
				item.imgUrl = '../../static/pdficon.jpeg' //默认为pdf

            item.uploadTime = new Date()
          })

          this.dataList=res.data.data;
          // console.log(this.dataList)
				}).catch(()=>{

						uni.showToast({
							title:"请求失败",
							icon:"none"
						})
					})
		},
		onLoad() {},
		onReady() {},
		methods: {
			//uni-search-bar的js
			search(res) {
				uni.showToast({
					title: '搜索：' + res.value,
					icon: 'none'
				})
			},
			input(e) {
				// 输入结束后，将值存入historyList
				this.searchVal = e;
				// console.log(e)
			},
			onclick(){
				uni.navigateTo({
					url:'/pages/index/search'
				})
			},
			information(id){
				uni.navigateTo({
					url:'/pages/index/details?id='+id+''
				})

			}
		}
	}
</script>

<style>
	.shuru{
		background-color: aliceblue;
		width: 75%;
		margin-left: 12%;
		border-radius: 6px;
	}
	.search{
		padding-top: 8px;

	}
	.body{
		background: #CFCFCF;
		overflow: hidden;
		padding-bottom: 50px;
	}
	.goods{
		display: flex;
		width: 100%;
		height: 120px;
		background: #fff;
		margin: 7px 0;
	}
	uni-image{
		width: 130px;
		height: 85px;
		margin-top: 17px;
	}
	text{
		font-size: 14px;
		color: #101010;

	}
	.content{
		margin-top: 10px;
		margin-right: 46px;

	}
	.content1{
		margin-top: 43px;
	}
	.price{
		color: #ff0000;
		font-size: 16px;
		margin-right: 65px;
		font-weight: 700;
	}
	.time{
		color: #9FA1A3;
		font-size: 12px;
	}
	.search[data-v-1ec26858]{
		padding-top: 3px;
	}
	/deep/.uni-searchbar__box{
		justify-content: flex-start;
		height: 28px;
	}
	.uni-searchbar{
		width: 90%;
		margin-left: 18px;
	}

</style>
